package cn.edu.scau.cmi.pengzhijie.client;



import cn.edu.scau.cmi.pengzhijie.sington.Chairman;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class SingletonClient extends Application{
	public static void main(String args[]) {
			launch(args);
	}
	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		Button button = new Button("创建");
		button.setLayoutX(130);
		button.setLayoutY(250);
		Text text = new Text("主席名称：");
		text.setLayoutX(50);
		text.setLayoutY(100);
		TextField textField = new TextField();
		textField.setMinWidth(80);
		textField.setLayoutX(105);
		textField.setLayoutY(85);
		Label textArea = new Label();
		textArea.setLayoutX(50);
		textArea.setLayoutY(110);
		Group group = new Group();
		group.getChildren().add(button);
		group.getChildren().add(text);
		group.getChildren().add(textArea);
		group.getChildren().add(textField);
		Scene scene = new Scene(group, 800, 800);
		primaryStage.setTitle("单例模式");
		primaryStage.setScene(scene);
		primaryStage.show();
	button.setOnAction(new EventHandler<ActionEvent>() {
			String str = "";
			@Override
			public void handle(ActionEvent event) {
				// TODO Auto-generated method stub
				Chairman chairman = null;
				String nowName = textField.getText();
				chairman = Chairman.getInstance(textField.getText());
				if(!nowName.equals(chairman.getName())) {
					 str = str + "当前主席为" + chairman.getName() + "," + chairman + ",不能创建" + nowName + "为主席" + "\n";
					 textArea.setText(str);
				} else {
					str = str + "创建主席成功，当前主席为：" + nowName + "," + chairman + "\n";
					textArea.setText(str);
				}
				
			}
		});
	}
	
}
